package mylab.io.base.property;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Maps;

import java.util.HashMap;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;
import mylab.io.base.sync.DefaultSynchro;
import mylab.io.base.sync.Synchro;
import mylab.utils.common.ReflectUtil;
import mylab.utils.common.StringUtil;


@Getter
@Setter
public class SyncAttrs {
    //同步回应超时时间
    protected String synchroImplClass;
    protected int timeoutSeconds = 5;
    protected Map<String, String> pairs = Maps.newHashMap();

    @JsonIgnore
    public Synchro getSynchro() {
        Synchro synchro;
        if (StringUtil.isNotEmpty(synchroImplClass)) {
            synchro = ReflectUtil.newInstance(synchroImplClass);
        } else {
            synchro = new DefaultSynchro();
        }

        synchro.regist(pairs);
        return synchro;
    }
}
